package lium.lbs.lbsim.activity

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.buz.hjcdriver.bean.ChargeResultBean
import com.lmlibrary.bean.ResponseBean
import lium.lbs.lbsim.utils.callbck.DialogCallback
import lium.lbs.lbsim.utils.ToastUtils
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_charge.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.adapter.WalletAdapter
import lium.lbs.lbsim.jgchat.application.GJApp
import lium.lbs.lbsim.pay.ChoosePayWayActivity
import java.util.HashMap

class ChargeActivity : BaseActivity() {
    lateinit var adapter: WalletAdapter
    override fun getLayoutId(): Int {
        return R.layout.activity_charge
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("充值")
        addOnClickListeners(R.id.btn_submit)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.btn_submit -> {
                submit()
            }
        }
    }


    private fun submit() {
        if (TextUtils.isEmpty(et_money_text.text.toString())) {
            ToastUtils.showToast("请输入充值金额")
            return
        }
        if (et_money_text.text.toString().toDouble() == 0.00) {
            ToastUtils.showToast("充值金额不能为0")
            return
        }
        val param = HashMap<String, String>()
        param["price"] = et_money_text.text.toString()
        postData("/member/chongZhi", param, object : DialogCallback<ResponseBean<ChargeResultBean>>(this) {
            override fun onSuccess(response: Response<ResponseBean<ChargeResultBean>>) {
                ToastUtils.showToast(response.body().msg)
                setData(response.body().data)

            }
        })

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 300) {
            finish()
            setResult(250)
        }
    }

    fun setData(chargeResultBean: ChargeResultBean) {
        val intent = Intent()
        intent.setClass(this, ChoosePayWayActivity::class.java)
        intent.putExtra("name", "充值")
        intent.putExtra("orderSN", chargeResultBean.orderNum)
        startActivityForResult(intent, 300)
    }

    override fun getNetWorkData() {

    }
}